package casa.depesos.app.com.dlg;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

import casa.depesos.app.com.activity.WebActivity;
import casa.depesos.app.com.adapter.BannerAdapter;
import casa.depesos.app.com.databinding.DlgMsgBinding;
import casa.depesos.app.com.http.data.Banner;
import casa.depesos.app.com.it.BannerClickListener;
import casa.depesos.app.com.utils.Report;

public class MsgDlg extends FullScreenDlg implements BannerClickListener {

    DlgMsgBinding binding;
    List<Banner> list;

    public MsgDlg setData(List<Banner> list) {
        this.list = list;
        return this;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DlgMsgBinding.inflate(inflater, container, false);
        binding.close.setOnClickListener(view -> dismiss());
        binding.banner.setLifecycleRegistry(getLifecycle())
                .setAdapter(new BannerAdapter(MsgDlg.this, true))
                .create(list);

        binding.banner.setAutoPlay(true);

        return binding.getRoot();
    }

    @Override
    public void onBannerClick(Banner banner) {
        Report.click("ACTION_UU_003");
        WebActivity.toSysWeb(banner.url);
    }
}
